package com.snake.springboot.custom.service.port.adapter.listener;


import com.alibaba.fastjson.JSONObject;
import com.snake.springboot.custom.api.model.pay.PayActModel;
import com.snake.springboot.custom.api.model.pay.PayActRetModel;
import com.snake.springboot.custom.api.model.pay.PayMsgModel;
import com.snake.springboot.custom.service.port.adapter.event.PayPlatEvent;
import com.snake.springboot.custom.service.port.adapter.event.PayPlatRetEvent;
import com.snake.springboot.custom.service.port.adapter.feign.PaymentFeignClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.snake.common.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * <p>支付网关模型
 * 类{@code PaymentListener} </br>
 * 创建时间2025/2/21 16:19
 * @author yangxt
 * @see
 */
@Component
public class PaymentListener {
    @Autowired
    private  PaymentFeignClient paymentFeignClient;

    private Logger log = LoggerFactory.getLogger(PaymentListener.class);

    @EventListener
    public void platGoPay(PayPlatEvent event){
        PayActModel data = event.getData();
        ResponseResult<PayMsgModel> result = paymentFeignClient.platGoPay(data);
        event.setResult(result.getData());
        log.info("支付网关返回结果:{}", JSONObject.toJSONString(result));

    }

    @EventListener
    public void platGoRet(PayPlatRetEvent event){
        PayActRetModel data = event.getData();
        ResponseResult<Object> result = paymentFeignClient.platGoRet(data);
        result.isUcc();

    }

}
